package common

import (
	"alertmanagerWebhook/config"
	"fmt"
)

type Transformer interface {
	Transform(notification config.Notification, platform string) (interface{}, error)  // 添加platform参数
}

type TransformerFactory struct{}

func NewTransformerFactory() *TransformerFactory {
	return &TransformerFactory{}
}

func (f *TransformerFactory) CreateTransformer(transformerType string) (Transformer, error) {
	switch transformerType {
	case "markdown", "dingding", "wechat":
		return NewMarkdownTransformer()  // 返回转换器和nil错误
	case "email":
		emailTransformer, err := NewEmailTransformer()
		if err != nil {
			return nil, err
		}
		return &emailAdapter{emailTransformer}, nil
	default:
		return nil, fmt.Errorf("unsupported transformer type: %s", transformerType)
	}
}

// Add this adapter struct to make EmailTransformer compatible with the interface
type emailAdapter struct {
	*EmailTransformer
}

func (a *emailAdapter) Transform(notification config.Notification, platform string) (interface{}, error) {
	// Ignore platform parameter for email
	return a.EmailTransformer.Transform(notification)
}

